package com.yt.hadoop.index;

/**
 * @Classname OneIndexReducer
 * @Description
 * @Date 2021/12/8 14:53
 * @Create by 杨涛
 */
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class OneIndexReducer extends Reducer<Text, IntWritable, Text, IntWritable>{

    IntWritable v = new IntWritable();

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values,Context context) throws IOException, InterruptedException {

        int sum = 0;

        // 1 累加求和
        for(IntWritable value: values){
            sum +=value.get();
            System.out.println("sum:--"+sum);
        }

        v.set(sum);

        System.out.println("写一次");
        // 2 写出
        context.write(key, v);
    }
}
